home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / bublbobl.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  6KB  |  235 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "cpu/z80/z80.h"
  12.  
  13.  
  14.  
  15. unsigned char *bublbobl_sharedram1,*bublbobl_sharedram2;
  16.  
  17.  
  18. READ_HANDLER( bublbobl_sharedram1_r )
  19. {
  20.     return bublbobl_sharedram1[offset];
  21. }
  22. READ_HANDLER( bublbobl_sharedram2_r )
  23. {
  24.     return bublbobl_sharedram2[offset];
  25. }
  26. WRITE_HANDLER( bublbobl_sharedram1_w )
  27. {
  28.     bublbobl_sharedram1[offset] = data;
  29. }
  30. WRITE_HANDLER( bublbobl_sharedram2_w )
  31. {
  32.     bublbobl_sharedram2[offset] = data;
  33. }
  34.  
  35.  
  36.  
  37. WRITE_HANDLER( bublbobl_bankswitch_w )
  38. {
  39.     unsigned char *RAM = memory_region(REGION_CPU1);
  40.  
  41.  
  42.     if ((data & 3) == 0) { cpu_setbank(1,&RAM[0x8000]); }
  43.     else { cpu_setbank(1,&RAM[0x10000 + 0x4000 * ((data & 3) - 1)]); }
  44. }
  45.  
  46. WRITE_HANDLER( tokio_bankswitch_w )
  47. {
  48.     unsigned char *RAM = memory_region(REGION_CPU1);
  49.  
  50.     cpu_setbank(1, &RAM[0x10000 + 0x4000 * (data & 7)]);
  51. }
  52.  
  53. WRITE_HANDLER( tokio_nmitrigger_w )
  54. {
  55.     cpu_cause_interrupt(1,Z80_NMI_INT);
  56. }
  57.  
  58. READ_HANDLER( tokio_fake_r )
  59. {
  60.   return 0xbf; /* ad-hoc value set to pass initial testing */
  61. }
  62.  
  63.  
  64.  
  65. static int sound_nmi_enable,pending_nmi;
  66.  
  67. static void nmi_callback(int param)
  68. {
  69.     if (sound_nmi_enable) cpu_cause_interrupt(2,Z80_NMI_INT);
  70.     else pending_nmi = 1;
  71. }
  72.  
  73. WRITE_HANDLER( bublbobl_sound_command_w )
  74. {
  75.     soundlatch_w(offset,data);
  76.     timer_set(TIME_NOW,data,nmi_callback);
  77. }
  78.  
  79. WRITE_HANDLER( bublbobl_sh_nmi_disable_w )
  80. {
  81.     sound_nmi_enable = 0;
  82. }
  83.  
  84. WRITE_HANDLER( bublbobl_sh_nmi_enable_w )
  85. {
  86.     sound_nmi_enable = 1;
  87.     if (pending_nmi)    /* probably wrong but commands go lost otherwise */
  88.     {
  89.         cpu_cause_interrupt(2,Z80_NMI_INT);
  90.         pending_nmi = 0;
  91.     }
  92. }
  93.  
  94.  
  95.  
  96. /***************************************************************************
  97.  
  98.  Bubble Bobble 68705 protection interface
  99.  
  100.  The following is ENTIRELY GUESSWORK!!!
  101.  
  102. ***************************************************************************/
  103. int bublbobl_m68705_interrupt(void)
  104. {
  105.     /* I don't know how to handle the interrupt line so I just toggle it every time. */
  106.     if (cpu_getiloops() & 1)
  107.         cpu_set_irq_line(3,0,CLEAR_LINE);
  108.     else
  109.         cpu_set_irq_line(3,0,ASSERT_LINE);
  110.  
  111.     return 0;
  112. }
  113.  
  114.  
  115.  
  116. static unsigned char portA_in,portA_out,ddrA;
  117.  
  118. READ_HANDLER( bublbobl_68705_portA_r )
  119. {
  120. //logerror("%04x: 68705 port A read %02x\n",cpu_get_pc(),portA_in);
  121.     return (portA_out & ddrA) | (portA_in & ~ddrA);
  122. }
  123.  
  124. WRITE_HANDLER( bublbobl_68705_portA_w )
  125. {
  126. //logerror("%04x: 68705 port A write %02x\n",cpu_get_pc(),data);
  127.     portA_out = data;
  128. }
  129.  
  130. WRITE_HANDLER( bublbobl_68705_ddrA_w )
  131. {
  132.     ddrA = data;
  133. }
  134.  
  135.  
  136.  
  137. /*
  138.  *  Port B connections:
  139.  *
  140.  *  all bits are logical 1 when read (+5V pullup)
  141.  *
  142.  *  0   W  enables latch which holds data from main Z80 memory
  143.  *  1   W  loads the latch which holds the low 8 bits of the address of
  144.  *               the main Z80 memory location to access
  145.  *  2   W  loads the latch which holds the high 4 bits of the address of
  146.  *               the main Z80 memory location to access
  147.  *         00 = read input ports
  148.  *         0c = access z80 memory at 0xfc00
  149.  *         0f = ????
  150.  *  3   W  selects Z80 memory access direction (0 = write 1 = read)
  151.  *  4   W  clocks main Z80 memory access (goes to a PAL)
  152.  *  5   W  clocks a flip-flop which causes IRQ on the main Z80
  153.  *  6   W  not used?
  154.  *  7   W  not used?
  155.  */
  156.  
  157. static unsigned char portB_in,portB_out,ddrB;
  158.  
  159. READ_HANDLER( bublbobl_68705_portB_r )
  160. {
  161.     return (portB_out & ddrB) | (portB_in & ~ddrB);
  162. }
  163.  
  164. static int address,latch;
  165.  
  166. WRITE_HANDLER( bublbobl_68705_portB_w )
  167. {
  168. //logerror("%04x: 68705 port B write %02x\n",cpu_get_pc(),data);
  169.  
  170.     if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
  171.     {
  172.         portA_in = latch;
  173.     }
  174.     if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02)) /* positive edge trigger */
  175.     {
  176.         address = (address & 0xff00) | portA_out;
  177. //logerror("%04x: 68705 address %02x\n",cpu_get_pc(),portA_out);
  178.     }
  179.     if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04)) /* positive edge trigger */
  180.     {
  181.         address = (address & 0x00ff) | ((portA_out & 0x0f) << 8);
  182.     }
  183.     if ((ddrB & 0x10) && (~data & 0x10) && (portB_out & 0x10))
  184.     {
  185.         if (data & 0x08)    /* read */
  186.         {
  187.             if ((address & 0x0f00) == 0x0000)
  188.             {
  189. //logerror("%04x: 68705 read input port %02x\n",cpu_get_pc(),address);
  190.                 latch = readinputport((address & 3) + 1);
  191.             }
  192.             else if ((address & 0x0f00) == 0x0c00)
  193.             {
  194. //logerror("%04x: 68705 read %02x from address %04x\n",cpu_get_pc(),bublbobl_sharedram2[address],address);
  195.                 latch = bublbobl_sharedram2[address & 0x00ff];
  196.             }
  197.             else
  198. logerror("%04x: 68705 unknown read address %04x\n",cpu_get_pc(),address);
  199.         }
  200.         else    /* write */
  201.         {
  202.             if ((address & 0x0f00) == 0x0c00)
  203.             {
  204. //logerror("%04x: 68705 write %02x to address %04x\n",cpu_get_pc(),portA_out,address);
  205.                 bublbobl_sharedram2[address & 0x00ff] = portA_out;
  206.             }
  207.             else
  208. logerror("%04x: 68705 unknown write to address %04x\n",cpu_get_pc(),address);
  209.         }
  210.     }
  211.     if ((ddrB & 0x20) && (~data & 0x20) && (portB_out & 0x20))
  212.     {
  213.         /* hack to get random EXTEND letters (who is supposed to do this? 68705? PAL?) */
  214.         bublbobl_sharedram2[0x7c] = rand()%6;
  215.  
  216.         cpu_irq_line_vector_w(0,0,bublbobl_sharedram2[0]);
  217.         cpu_set_irq_line(0,0,HOLD_LINE);
  218.     }
  219.     if ((ddrB & 0x40) && (~data & 0x40) && (portB_out & 0x40))
  220.     {
  221. logerror("%04x: 68705 unknown port B bit %02x\n",cpu_get_pc(),data);
  222.     }
  223.     if ((ddrB & 0x80) && (~data & 0x80) && (portB_out & 0x80))
  224.     {
  225. logerror("%04x: 68705 unknown port B bit %02x\n",cpu_get_pc(),data);
  226.     }
  227.  
  228.     portB_out = data;
  229. }
  230.  
  231. WRITE_HANDLER( bublbobl_68705_ddrB_w )
  232. {
  233.     ddrB = data;
  234. }
  235.